home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / ARGONET / PD / MATHS / RLAB / RLAB125.ZIP / !RLaB / examples / plot_test < prev    next >
Text File  |  1995-05-20  |  6KB  |  289 lines

  1. #
  2. # Test 2-D plots
  3. #
  4.  
  5. plstart (2,2);
  6.  
  7. x = (0.25:4:.25)';
  8.  
  9. //-----------------------------------------------------------------//
  10. pltitle ("Multiple Line Colors and Styles");
  11. xlabel ("X-axis Label");
  12. ylabel ("Y-axis Label");
  13. plot ( [x, x, 2*x, 3*x] );
  14.  
  15. subplot (4);
  16. pltitle ("Multiple Point Colors and Styles");
  17. plstyle ("point");
  18. plot ( [x, x, 2*x, 3*x] );
  19. pause ("Type RETURN to continue");
  20.  
  21. //-----------------------------------------------------------------//
  22. pltitle("Plot 1, No Grid");
  23. plgrid ("", "");
  24. plot ([x,exp(-x*0.5)]);
  25.  
  26. pltitle("Plot 2, Grid Box Only");
  27. plgrid ("bc", "bcv");
  28. plot ([x,2*x,3*x,4*x]);
  29.  
  30. pltitle("Plot 3, Box, and Coordinates");
  31. plgrid ("bcnt", "bcnvt");
  32. plot ([x,-2*x,2*x]);
  33.  
  34. pltitle("Plot 4, ");
  35. plgrid ("bcngst", "bcngvst");
  36. plot ([x,x,cos(2*pi*x*0.25)]);
  37. pause ("Type RETURN to continue");
  38.  
  39. plgrid ();  # Reset axis
  40.  
  41. //-----------------------------------------------------------------//
  42. # Show off axis types
  43. pltitle("Linear Axes");
  44. plgrid();
  45. plot ([x,exp(-x*0.5)]);
  46.  
  47. pltitle("Log X - Axis");
  48. plgrid("bcngstl");
  49. plot ([x,exp(-x*0.5)]);
  50.  
  51. pltitle("Log Y - Axis");
  52. plgrid("bcngst", "bcngstlv");
  53. plot ([x,exp(-x*0.5)]);
  54.  
  55. pltitle("Log  Axes");
  56. plgrid("bcngstl", "bcngstlv");
  57. plot ([x,exp(-x*0.5)]);
  58. pause ("Type RETURN to continue");
  59.  
  60. plgrid ();  # Reset axis
  61.  
  62.  
  63. //-----------------------------------------------------------------//
  64. # Data with different scales
  65. y = (0.5:6:.2)';
  66. pltitle("Plot Data with Different Scales");
  67. plgrid ();
  68. plot (<< [x,exp(-x*0.5)] ; [y, exp (y*0.25), exp(y*0.1)] >>);
  69.  
  70. # Histograms
  71.  
  72. rand("normal", 0, pi);
  73. r = rand(2000,1);
  74.  
  75. plgrid ();
  76. pltitle("Histogram, Default No. of Bins");
  77. plhist (r);
  78.  
  79. pltitle("Histogram, 30 Bins");
  80. plgrid ();
  81. plhist (r, 30);
  82.  
  83. pltitle("2 Histograms, 30 Bins");
  84. plgrid ();
  85. plhist ([r, 2*r], 30);
  86. pause ("Type RETURN to continue");
  87.  
  88. //-----------------------------------------------------------------//
  89.  
  90. # Some more histograms...
  91.  
  92. xlabel(); ylabel(); plgrid (); plstyle();
  93. pltitle("Histogram, Default No. of Bins");
  94. plhist (r);
  95.  
  96. xlabel(); ylabel(); plgrid (); plstyle("line-point");
  97. pltitle("Histogram, Default No. of Bins");
  98. plhistx (r);
  99.  
  100. xlabel(); ylabel(); plgrid (); plstyle();
  101. pltitle("Histogram, 30 Bins");
  102. plgrid ();
  103. plhist (r, 30);
  104.  
  105. xlabel(); ylabel(); plgrid (); plstyle("line-point");
  106. pltitle("Histogram, 30 Bins");
  107. plhistx (r, 30);
  108. pause ("Type RETURN to continue");
  109.  
  110. //-----------------------------------------------------------------//
  111. # Make 3D data
  112.  
  113. # Sombrero
  114.  
  115. NX = 20;
  116. NY = 20;
  117. xx = zeros (1, NX);
  118. yy = zeros (1, NY);
  119. for (i in 1:NX) { xx[i] = (i - NX/2)/(NX/2); }
  120. for (i in 1:NY) { yy[i] = (i - NY/2)/(NY/2); }
  121.  
  122. zz = zeros (NX, NY);
  123.  
  124. for (i in 1:NX)
  125. {
  126.   for (j in 1:NY)
  127.   {
  128.     r = sqrt (xx[i]^2 + yy[j]^2);
  129.     zz[i;j] = exp (-r * r) * cos (2*pi*r);
  130.   }
  131. }
  132.  
  133. # Now create some plots
  134.  
  135. pltitle("3-D Plot, Sombrero");
  136. plmesh (<< x = xx; y = yy; z = zz>>);
  137.  
  138. # Sin - Cos surface
  139.  
  140. x1 = -3:3:.2;
  141. y1 = -3:3:.2;
  142. z1 = zeros (x1.n, y1.n);
  143.  
  144. for (i in 1:x1.n)
  145. {
  146.   for(j in 1:y1.n)
  147.   {
  148.     z1[i;j] = sin(y1[j]) * cos(x1[i]);
  149.   }
  150. }
  151.  
  152. pltitle("3-D Plot, Cos-Sine Surface");
  153. plmesh (<< x = x1; y = y1; z = z1>>);
  154.  
  155. # Slanted plane
  156.  
  157. x2 = 1:10;
  158. y2 = 1:10;
  159. z2 = zeros (x2.n, y2.n);
  160. for (i in 1:x2.n) { z2[i;] = i*ones(1,y2.n); }
  161.  
  162. pltitle("3-D Plot, Plane");
  163. plmesh (<< x = x2; y = y2; z = z2>>);
  164.  
  165. # Two Slanted planes
  166. z3 = -2*z2;
  167. pltitle("3-D Plot, 2 - Planes");
  168. plmesh (<< x = x2; y = y2; z = z2>>, <<x = x2; y = y2; z = z3 >>);
  169.  
  170. pause ("Type RETURN to continue");
  171.  
  172. //-----------------------------------------------------------------//
  173.  
  174. # Now show 3-D viewing angles
  175.  
  176. pltitle("3-D Plot, Sombrero, Default View, Alt = 60, Az = 45");
  177. plmesh (<< x = xx; y = yy; z = zz>>);
  178.  
  179. pltitle("3-D Plot, Sombrero, Alt = 10, Az = 10");
  180. plalt(10); 
  181. plaz(10);
  182. plmesh (<< x = xx; y = yy; z = zz>>);
  183.  
  184. pltitle("3-D Plot, Sombrero, Alt = 20, Az = 30");
  185. plalt(20); 
  186. plaz(30);
  187. plmesh (<< x = xx; y = yy; z = zz>>);
  188.  
  189. pltitle("3-D Plot, Sombrero, Alt = 80, Az = 60");
  190. plalt(80); 
  191. plaz(60);
  192. plmesh (<< x = xx; y = yy; z = zz>>);
  193.  
  194. pause ("Type RETURN to continue");
  195.  
  196. //-----------------------------------------------------------------//
  197.  
  198. #
  199. # Simple contour plotting demonstration
  200. #
  201.  
  202. NX = 20;
  203. NY = 20;
  204. xx = zeros (1, NX);
  205. yy = zeros (1, NY);
  206. for (i in 1:NX) { xx[i] = (i - NX/2)/(NX/2); }
  207. for (i in 1:NY) { yy[i] = (i - NY/2)/(NY/2); }
  208.  
  209. zz = zeros (NX, NY);
  210.  
  211. for (i in 1:NX)
  212. {
  213.   for (j in 1:NY)
  214.   {
  215.     r = sqrt (xx[i]^2 + yy[j]^2);
  216.     zz[i;j] = exp (-r * r) * cos (2*pi*r);
  217.   }
  218. }
  219.  
  220. # Sin - Cos surface
  221.  
  222. x1 = -3:3:.2;
  223. y1 = -3:3:.2;
  224. z1 = zeros (x1.n, y1.n);
  225.  
  226. for (i in 1:x1.n)
  227. {
  228.   for(j in 1:y1.n)
  229.   {
  230.     z1[i;j] = sin(y1[j]) * cos(x1[i]);
  231.   }
  232. }
  233.  
  234. # Now create some plots
  235.  
  236. xlabel("X-Axis");
  237. ylabel("Y-Axis");
  238. pltitle ("Contour Demonstration");
  239. plalt();
  240. plaz();
  241. plmesh (<< x = xx; y = yy; z = zz>>);
  242.  
  243. xlabel("X-Axis");
  244. ylabel("Y-Axis");
  245. pltitle ("Contour Demonstration");
  246. plalt();
  247. plaz();
  248. plcont (<< x = xx; y = yy; z = zz>>);
  249.  
  250. xlabel("X-Axis");
  251. ylabel("Y-Axis");
  252. pltitle ("Contour Demonstration");
  253. plalt();
  254. plaz();
  255. plmesh (<< x = x1; y = y1; z = z1>>);
  256.  
  257. xlabel("X-Axis");
  258. ylabel("Y-Axis");
  259. pltitle ("Contour Demonstration");
  260. plalt();
  261. plaz();
  262. plcont (<< x = x1; y = y1; z = z1>>);
  263.  
  264. pause ("Type RETURN to continue");
  265.  
  266. //-----------------------------------------------------------------//
  267.  
  268. // Now try some diff scale settings (log)
  269.  
  270. plgrid3(); 
  271. pltitle("3-D Plot, Sombrero");
  272. plmesh (<< x = xx; y = yy; z = zz>>);
  273.  
  274. plgrid3("bnstul", "bnstul");
  275. pltitle("3-D Plot, Sombrero (log-scales)");
  276. plmesh (<< x = xx+5; y = yy+5; z = zz>>);
  277.  
  278. plgrid3(); 
  279. plaxis ("log", "log");
  280. pltitle("3-D Plot, Cos-Sine Surface");
  281. plmesh (<< x = x1; y = y1; z = z1>>);
  282.  
  283. plgrid3("bnstul", "bnstul");
  284. plaxis ("log", "log");
  285. pltitle("3-D Plot, Cos-Sine Surface (log-scales)");
  286. plmesh (<< x = x1+5; y = y1+5; z = z1>>);
  287.  
  288. pause ("Type RETURN to continue");
  289.